# 定义序列化器
from rest_framework import serializers
from .models import Nav, Category, Banner


# 导航菜单的序列化器
class NavModelSerializer(serializers.ModelSerializer):
    """
    导航菜单的序列化器
    """
    class Meta:
        model = Nav
        # 指定哪些属性可以序列化
        fields = ["name", "link", "is_http"]

# 首页分类的子菜单的序列化器
class ChildrenSerializer(serializers.ModelSerializer):
    class Meta:
        model=Category
        fields=['cname','id']
# 首页分类的序列化器
class CategorySerializer(serializers.ModelSerializer):
    children=ChildrenSerializer(many=True)
    class Meta:
        model=Category
        fields='__all__'

# 轮播图的序列化器
class BannerModelSerializer(serializers.ModelSerializer):
    """
    轮播广告的序列化器
    """
    class Meta:
        model = Banner
        fields = ["image", "name", "link", "is_http"]